import Vue from 'vue'
import Router from 'vue-router'
import MuseUi from 'muse-ui'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
import 'muse-ui/dist/muse-ui.css'
import 'muse-ui/dist/theme-light.css'
import VueLazyload from 'vue-lazyload'
import music from '@/components/music/music'
import main from '@/components/main/main'
import user from '@/components/user/user'
import recommend from '@/components/recommend/recommend'
import songList from '@/components/songList/songList'
Vue.use(VueLazyload)
Vue.use(MuseUi)
Vue.use(VueAwesomeSwiper)
Vue.use(Router)
const routes = [
  {
    path: '/',
    redirect: '/main',
    component: main
  },
  {
    path: '/main',
    component: main,
    children: [
      {
        path: '',
        component: recommend,
        meta: { keepAlive: true }
      },
      {
        path: 'recommend',
        component: recommend,
        meta: { keepAlive: true }
      },
      {
        path: 'songList',
        component: songList,
        meta: { keepAlive: true }
      }
    ]
  },
  {
    path: '/music',
    component: music
  },
  {
    path: '/user',
    component: user
  }
]
const router = new Router({
  mode: 'history',
  linkActiveClass: 'active',
  base: 'zgf',
  scrollBehavior: (to, from, savedPosition) => {
    console.log(document.body.scrollTop)
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
      }
      return { x: 0, y: to.meta.savedPosition || 0 }
    }
  },
  routes: routes
})
export default router
